//C++实现队列，可以用list或者vector实现栈。


#include <iostream>
#include <vector>
#include <list>

using namespace std;

class MyQueue {
public:
    void enqueue(int value) {
        data.push_back(value);
    }

    int dequeue() {
        if (data.empty()) {
            throw std::runtime_error("Queue is empty");
        }
        int value = data.front();
        data.erase(data.begin());
        return value;
    }

    int front() const {
        if (data.empty()) {
            throw std::runtime_error("Queue is empty");
        }
        return data.front();
    }

    bool empty() const {
        return data.empty();
    }

private:
    std::vector<int> data;
};

#include <iostream>
#include <list>

class Queue {
public:
    void enqueue(int value) {
        data.push_back(value);
    }

    int dequeue() {
        if (data.empty()) {
            throw std::runtime_error("Queue is empty");
        }
        int value = data.front();
        data.pop_front();
        return value;
    }

    bool empty() const {
        return data.empty();
    }

private:
    std::list<int> data;
};


#include <iostream>
class Stack {
private:
    int* arr;
    int top;
    int capacity;

public:
    Stack(int size = 10) {
        arr = new int[size];
        capacity = size;
        top = -1;
    }

    ~Stack() {
        delete[] arr;
    }

    void push(int value) {
        if (top == capacity - 1) {
            std::cout << "Stack overflow." << std::endl;
            return;
        }
        arr[++top] = value;
    }

    void pop() {
        if (top == -1) {
            std::cout << "Stack underflow." << std::endl;
            return;
        }
        top--;
    }

    int peek() {
        if (top == -1) {
            std::cout << "Stack is empty." << std::endl;
            return -1;
        }
        return arr[top];
    }

    bool isEmpty() {
        return top == -1;
    }
};

class Stack {
private:
    vector<int> data;  // 存储栈元素
public:
    void push(int val) {
        data.push_back(val);  // 将元素插入到vector的末尾
    }

    void pop() {
        data.pop_back();  // 删除vector末尾的元素
    }

    int top() {
        return data.back();  // 返回vector末尾的元素
    }

    bool empty() {
        return data.empty();  // 判断vector是否为空
    }
};